Avoiding collisions under topological constraints in variational problems coming from celestial mechanics