Thames Water has been fined £3.34m after millions of litres of raw sewage flooded two rivers near Gatwick.