The person so depositing a sum of money in lieu of a bond, recognizance or undertaking shall be entitled upon application to the court wherein such deposit has been made, and subject to the order under which such fund is held, to receive back such sum of money whenever the purposes for which it has been received and deposited have been accomplished and the person would have been entitled to be released without payment or further payment of any sum from all liability on the required bond, recognizance or undertaking had it been given in lieu of such deposit of money.