Effect of the boundary conditions in the behavior of the optimal constant of some Caffarelli-Kohn-Nirenberg inequalities. Application to some doubly critical nonlinear elliptic problems