In any prosecution for an offense against the state or any political subdivision thereof, when money has been deposited by or on behalf of the defendant upon a judgment for the payment of a fine and costs, the clerk shall, under the direction of the court, apply the money deposited in satisfaction of such fine and costs and return the remainder to the depositor.