There might be a better way, but in this case you could define that one field of the mapping table always contains the lower key and the other the higher:
(foo_id_lower integer references table1(foo_id) not null, foo_id_higher integer references table1(foo_id) not null, constraint foo_id_lower < foo_id_higher)
(not sure about the constraint syntax)