  The purpose of this paper is to investigate the following invariance equation
involving two $2$-variable generalized Bajraktarevi\'c means, i.e., we aim to
solve the functional equation $$
  f^{-1}\bigg(\frac{p_1(x)f(x)+p_2(y)f(y)}{p_1(x)+p_2(y)}\bigg)+g^{-1}\bigg(\frac{q_1(x)g(x)+q_2(y)g(y)}{q_1(x)+q_2(y)}\bigg)=x+y
\qquad(x,y\in I), $$ where $I$ is a nonempty open real interval and
$f,g:I\to\mathbb{R}$ are continuous, strictly monotone and
$p_1,p_2,q_1,q_2:I\to\mathbb{R}_+$ are unknown functions. The main result of
the paper shows that, assuming four times continuous differentiability of $f$,
$g$, twice continuous differentiability of $p_1$ and $p_2$ and assuming that
$p_1$ differs from $p_2$ on a dense subset of $I$, a necessary and sufficient
condition for the equality above is that the unknown functions are of the form
$$
  f=\frac{u}{v},\qquad g=\frac{w}{z},\qquad \mbox{and}\qquad
  p_1q_1=p_2q_2=vz, $$ where $u,v,w,z:I\to\mathbb{R}$ are arbitrary solutions
of the second-order linear differential equation $F''=\gamma F$
($\gamma\in\mathbb{R}$ is arbitrarily fixed) such that $v>0$ and $z>0$ holds on
$I$ and $\{u,v\}$ and $\{w,z\}$ are linearly independent.
