table.insert by default inserts at the end of the array part of the table.
the array part is whichever n,n+1,...,n+k continuous sequence of positive whole numbers that lua decides is the array part.
if you only ever used table.insert to insert stuff into your objects table, then you can simply iterate over it using ipairs instead of pairs, since the latter does things in an undefined order.
i would ask though, how do you differentiate between objects in what you want to remove? by which field? because putting a table in a local variable called lock does nothing when you insert it into objects; the table itself won't store that it was the 'lock' table, you'd need to store that separately... that said, without these answers, i can only guess and give general advice.
Also, as the ninja below me said, if you don't want holes in your table, using table.remove is an easy solution.