Matching algorithm, match pairs: what would be the right way to do it?
This isn't sorting: it's matching. The vertices of your graph are the data rows and there's an edge between two vertices if the two rows are compatible for pairing (e.g., have no difference bigger than&nbsp;3, or whatever criterion you want to use).  You're looking for a maximum matching, i.e., a biggest-possible pairing between compatible rows.

It's unclear in your question but you might instead want to define a weighted graph where the weight of an edge is the amount of compatibility (e.g., rows that are very close have a high weight, rows that aren't so close have a low weight, rows that are incompatible have no edge, as before) and compute a maximum-weight matching.