Topological changes of the photospheric magnetic field inside active regions: A prelude to flares?