  Despite the widespread use of gradient-based algorithms for optimizing
high-dimensional non-convex functions, understanding their ability of finding
good minima instead of being trapped in spurious ones remains to a large extent
an open problem. Here we focus on gradient flow dynamics for phase retrieval
from random measurements. When the ratio of the number of measurements over the
input dimension is small the dynamics remains trapped in spurious minima with
large basins of attraction. We find analytically that above a critical ratio
those critical points become unstable developing a negative direction toward
the signal. By numerical experiments we show that in this regime the gradient
flow algorithm is not trapped; it drifts away from the spurious critical points
along the unstable direction and succeeds in finding the global minimum. Using
tools from statistical physics we characterize this phenomenon, which is
related to a BBP-type transition in the Hessian of the spurious minima.
