Recall the the angle sum identity for cosine.
\(\cos(\theta+\varphi)=\cos\theta\cos\varphi-\sin\theta\sin\varphi\)
\(\cos(\theta-\varphi)=\cos\theta\cos\varphi+\sin\theta\sin\varphi\)
Adding the two equations together gives
\(\cos(\theta+\varphi)+\cos(\theta-\varphi)=2\cos\theta\cos\varphi\)
while subtracting gives
\(\cos(\theta+\varphi)-\cos(\theta-\varphi)=-2\sin\theta\sin\varphi\)
Replacing \(\theta=3x\) and \(\varphi=-x\), you get
\(\dfrac{\cos2x-\cos4x}{\cos2x+\cos4x}=\dfrac{\cos(3x+(-x))-\cos(3x-(-x))}{\cos(3x+(-x))+\cos(3x-(-x))}=\dfrac{-2\sin3x\sin(-x)}{2\cos3x\cos(-x)}\)
Finally, \(\cos(-x)=\cos x\), so you get the second expression.