Your washing machine needs to have a trap installed on the drain line. The trap can be a helpful point of cleanout if lint builds up inside the drain. It also prevents sewer gas from traveling up the drainpipe and escaping out through your washing machine. Not only does sewer gas smell terrible, but also it is a health and safety risk. Fumes from the methane gas can trigger headaches. In high enough concentrations, sewer gas can be flammable, which you do not want to have around appliances such as a clothes dryer.
To meet standard building codes, install the trap on the drainpipe for the washing machine between 6 and 18 inches from the floor; 18 inches is the maximum height level for a P-trap on a washing machine. The trap can be made from PVC piping or brass. If it is made from PVC, you can install it inside the walls for a neater appearance. If it is made of brass, then it needs to be outside the wall. Whether it is inside or out, the limit of 18 inches for maximum height remains the same.
The standpipe drain that the trap connects to should be a minimum of 2 inches in diameter. If you have a large washer or tend to do a lot of laundry, you can install a larger pipe. You should especially consider doing so if you might install more water-using appliances that need to drain into the standpipe. The increased room allows for faster water flow and will not affect drainage if it is larger than you really need.
To be sure any new plumbing or construction you add to your home is up to the building codes in your local municipality; it is safest to draw up plans and then consult with a building inspector. The inspector can let you know if there are any violations. This protects you from dealing with costly changes that must be made to bring your laundry room up to code after your home is inspected and discovered to be out of compliance.