Get some paraformaldehyde crystals (MildewGaz, etc.) ... but must be 'paraformaldehyde'
Get a LARGE heavy walled plastic bag ... and a vacuum cleaner or shop vac.
One or 2 SHEETS of fabric softner (Bounce™, etc.)
Remove the covers from the cushions and wash them.
Pour the paraformaldehyde crystals onto a sheet of fabric (muslin or old bedsheet material) and wrap it up into a 'wad'. The fabric will 'contain' the paraF. and prevent it from 'getting all over' the foam.
Roll the foam as tight as possible, with the 'wad' containing the paraF crystals inside it , add the fabric softner sheets ...... and STUFF it into the plastic bag.
Close the bag but make a 'neck' into which you can put the vacuum hose from the shop vac or vacuum cleaner.
Hold the 'neck' of the bag tightly around the vacuum hose and 'suck-down' the foam into a teeny 'little knot'. Quickly remove the vacuum hose and seal the bag 'neck' with string, etc. Let sit a day or so or until the outside air pressure refills the bag & foam... then pump
-down again several times.
Let the foam sit in the bag at least a week (will slowly gain air but no matter).
Then remove the 'wad' containing the paraformaldehyde and suck the foam down several times to remove the paraformaldehyde gas and exchange that gas for 'air'.
The paraformalhyde will KILL any mold/mildew and its spores inside the foam, will exchange the foul trapped air with 'good' air. This will usually correct the foul odor if the mildew hasnt 'gotten too far' (growth) inside the foam. If this method doesnt work, then you have to get new foam.
Do this out in the open/outside as paraformaldehyde gas is harmful to humans. READ all the cautions on the paraF package and follow them to the letter as if misused paraformaldehyde is quite harmful.
To prevent mildew, etc. 'uptake' go to an upholstery supply and 'overlay' all the foam inside your cushions with 'latex membrane' ... leaving only small sections of the 'sides' uncovered with membrane so that .... you dont get a 'whoopie cushion' effect when you sit down on them. Cover the foam with latex (leaving some small 'breathing holes'), dust the membrane with a wee bit of talc ... and stuff them back inside of the covering material.