Getting rid of double delta function in Feynman rules

[1] A very simple example of feynman rule for scalar fields.

After computing the diagram i have got the following:

$$-i(2\pi)^4g^2\int d^4q \frac{i}{q^2 -m^2c^2}\delta^{(4)}(p_1 - p_3 -q) \delta^{(4)}(p_2 + q -p_4)$$

I'm a little confused about how the integral approached, it integrated over one delta function to get

$$-ig^2\frac{1}{(p_4 - p_2)^2 -m^2c^2}(2\pi)^4\delta^{(4)}(p_1+p_2 - p_3 - p_4)$$

Am i allowed to do that? I mean I have $q$ in both delta functions. Can I just integrate over one of it? It doesn't sound right. What I'm missing here?

-
If you like this question you may also enjoy reading this Phys.SE post. –  Qmechanic Apr 18 '13 at 13:39
That looks correct to me. Consider the basic property of the delta functions $$\int dx f(x) \delta(x-a) = f(a).$$ Nothing forbids $f(x)$ to be a composite function, for example $f(x) \equiv g(x)\delta(x-b)$, so $f(a) = g(a) \delta(a-b)$. Hence we get, $$\int dx f(x) \delta(x-a) \equiv \int dx \, g(x)\delta(x-b) \delta(x-a) = g(a)\delta(a-b).$$