Optimization, Fast and Slow: Optimally Switching Between Local and Bayesian Optimization