Get all new queue items and remove duplicates?

If have a queue where items may be add and processed multiple times, so I cannot use the Unique Reference setting. But if the same reference ID is in the queue multiple times with a “new” status, I only want to process the most recent one added and mark the older ones as “Abandoned.” Is there any way to do this?