Sorry about the previous comment.

Actually, it does work. 
If case totalNeededAmount is not reached, _selectUnspend returns an empty array. The next call will scan the whole array, looking for outputs with less confirmations.

What this is not taking in account, thought, is that outputs with confirmations >=6 dont have preference in case they dont sum up the totalNeededAmount. Should I modify that?