If a city or town, whether or not any of its streets are designated as forming a part of a state highway, is unable to construct, repair, or maintain its streets for good cause, or if it is in need of engineering assistance to construct, repair, or maintain any of its streets, it may authorize the department to perform such construction, repair, or maintenance, or it may secure necessary engineering assistance from the department, to the extent of the funds credited or to be credited in the motor vehicle fund for payment to the city or town. Any sums due from a city or town for such purposes shall be paid on vouchers approved and submitted by the department from moneys credited to the city or town in the motor vehicle fund, and the amount of the payments shall be deducted from funds which would otherwise be paid to the city or town from the motor vehicle fund. The department may in certain special cases, in its discretion, enter into an agreement with the governing officials of the city or town for the performance of such work or services, the terms of which shall provide for reimbursement of the motor vehicle fund for the benefit of the state's share of the fund by the city or town of the cost thereof from any funds of the city or town on hand and legally available for the work or services. The city or town may, by resolution, authorize the legislative authority of the county in which it is located, to perform any such construction, repair, or maintenance, and the work shall be paid for by the city or town at the actual cost thereof as provided for payment for work performed on city streets, and any payment received therefor by a county shall be deposited in the county road fund to be expended under the same provisions as are imposed upon the funds used to perform the construction, repair, or maintenance.