§ 45. Disposal of fines and moneys recovered. Except as otherwise provided in this chapter, all moneys recovered, either as fines, penalties, forfeitures or otherwise, for the violation of any of the provisions of this chapter, or of any other law the enforcement of which is within the jurisdiction of the department, or of the rules of the department, and all bail forfeited by persons charged with such violations, shall be the property of the state. Moneys so recovered by town justices shall be paid to the state comptroller in accordance with the provisions of section twenty-seven of the town law and moneys so recovered by village justices shall be paid to the state comptroller in accordance with the provisions of section 4-410 of the village law. The same disposal shall be made of all moneys recovered upon any bond given by any officer by virtue of the provisions of this chapter. Provided, however, that any such moneys collected as fines, penalties or forfeitures as a result of a prosecution for a violation of any of the provisions of article sixteen and sixteen-a of this chapter and all bail forfeited by persons charged with such violations shall be the property of the county or city, as the case may be, in which the alleged offense was prosecuted and shall be paid to the treasurer, or corresponding fiscal officer, of such county or city, except that any such moneys and any such bail forfeitures, collected by the town justices or by village justices shall be paid to the state comptroller in accordance with section twenty-seven of the town law and section 4-410 of the village law, respectively.