(a) The defendant may at the time of his arrest, instead of giving bail, deposit with the marshal the amount mentioned in the writ. Thereupon the marshal shall give the defendant a certificate of the deposit made and the defendant shall be discharged from custody.
(b) The marshal shall, within ten days after the deposit, pay the same into the court, and take from the clerk receiving the same two certificates of such payment, the one of which he shall deliver to the plaintiff or his attorney and the other to the defendant. For any default in making such payment, the same proceedings may be had on the official bond of the marshal to collect the sum deposited as in other cases of delinquency.
(c) If money is deposited, as provided in subsections (a) and (b) of this section, bail may be given and justified upon notice, at any time before judgment, and on the filing of the undertaking and justification with the clerk the money deposited shall be refunded by such clerk to the defendant.
(d) When money has been deposited, if it remains on deposit at the time of an order or judgment for the payment of money to the plaintiff, the clerk shall, under the direction of the court, apply the same in satisfaction thereof, and, after satisfying the judgment, shall refund the surplus, if any, to the defendant. If the judgment is in favor of the defendant the clerk shall refund to him the whole sum deposited and remaining unapplied.