A matching estimator based on a bilevel optimization problem