Enhanced stability of flows through contraction channels: combining shape optimisation and linear stability analysis