Let a function $y=f(x_1,x_2)$, and where $f_1$ and $f_2$ denote first partial derivatives and $f_{11}$ etc second partials.
The elasticity of substitution was defined by Hicks in order to answer the question
"How does the input factor ratio changes as the ratio of factor prices changes?"
To be an elasticity, it had to be dimensionless, a relative measure.
So Hicks' original concept starts conceptually with the expression
$$\sigma = -\frac{\frac{d(x_1/x_2)} {(x_1/x_2)}}{\frac{d (w_1/w_2)} {(w_1/w_2)}}, \tag{1}$$
where $f$ is now a production function, $w_1, w_2$ are the factor prices, and the operator "$d$" is best viewed as a differential, linking also to its discrete analogue "$\Delta$".
Making it even more an economic concept, assume now that the firm is a cost-minimizer.
Then, at optimized behavior we have
$$\frac{w_1}{w_2} = \frac{f_1}{f_2}, \tag{2}$$
...and this explains why we should care about such a metric, and why it is a measure of "substitutability" (a measure not the measure): as relative factor prices change, how much do the factor ratio changes? This takes into account both the economic, behavioral aspect of cost minimization, and the available production technology.
So we can write
$$\sigma = -\frac{\frac{d(x_1/x_2)} {(x_1/x_2)}}{\frac{d (f_1/f_2)} {(f_1/f_2)}}. \tag{3}$$
Note that, if one doesn't know the economic motivation, then eq. $(3)$ (which is exactly the same as the one used by the OP), can be seen as a purely mathematical metric of the bivariate function: the relative change of the ratio of the two variables over the relative change of the ratio of their first derivatives.
The economic mid-way, is to say, "the relative change of input ratio over the relative change of the MRS". But this retains economic meaning only if we keep reminding ourselves that inputs are chosen so that their ratio of marginal products, the MRS, equals the factor price ratio at optimized behavior.
After certain mathematical manipulations (see Silberberg The Structure of Economics 2nd ed., ch. 9.4), one gets
$$\sigma = \frac{-f_1f_2(f_1x_1 + f_2x_2)}{x_1x_2(f_2^2f_{11}-2f_1f_2f_{12}+f_1^2f_{22})}.$$
All the above do not require the function $f$ to be homogeneous, nor $\sigma$ to be a constant.
The above expression of course simplifies greatly if the production function is homogeneous of degree one.