What if the vectors are of different sizes?
Perhaps they always are of the same size (given the comment in the function header).
Pretty cryptic function. It's taken me a while to understand it, and I'm still not sure I've understood it ... :-)

It seems the order of the metadatas is not important.
Perhaps both vectors should be ordered before they are compared?
At least it would make the function very easy to understand.

NTC, I think ...