Thames Water’s plans for a £3 billion loan have been approved by a judge, designed to prevent it from going bust in the near future.