MAINT: avoid redundant evaluation of user-provided function in l-bfgs-b optimization

closes https://github.com/scipy/scipy/issues/4076